home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / bin / usb-creator < prev    next >
Encoding:
Text File  |  2009-04-17  |  2.6 KB  |  76 lines

  1. #!/usr/bin/python
  2.  
  3. # Copyright (C) 2008 Canonical Ltd.
  4.  
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License version 3,
  7. # as published by the Free Software Foundation.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16.  
  17. import sys
  18. import optparse
  19. import os
  20. import linecache
  21. from usbcreator.gtk_frontend import GtkFrontend
  22.  
  23. trace_file = None
  24.  
  25. def _traceit(frame, event, arg):
  26.     if event == "line":
  27.         lineno = frame.f_lineno
  28.         filename = frame.f_globals["__file__"]
  29.         if (filename.endswith(".pyc") or
  30.             filename.endswith(".pyo")):
  31.             filename = filename[:-1]
  32.         name = frame.f_globals["__name__"]
  33.         line = linecache.getline(filename, lineno)
  34.         print >>trace_file, "%s:%s: %s" % (name, lineno, line.rstrip())
  35.         trace_file.flush()
  36.     return _traceit
  37.  
  38. usage = '%prog [options]'
  39. parser = optparse.OptionParser(usage=usage, version='0.1.11')
  40. parser.set_defaults(
  41.     safe=False,
  42.     iso=None,
  43.     persistent=True,
  44.     trace=False)
  45. parser.add_option('-s', '--safe', dest='safe', action='store_true',
  46.                   help='choose safer options when constructing the USB '
  47.                   'disk (may slow down the boot process).')
  48. parser.add_option('-i', '--iso', dest='iso',
  49.                   help='provide a source ISO to pre-populate the UI.')
  50. parser.add_option('-n', '--not_persistent', dest='persistent', action="store_false",
  51.                   help='disable persistent setting by default in the UI')
  52. parser.add_option('-t', '--trace', dest='trace', action='store_true',
  53.                   help='create a ~/.usb-creator.trace file')
  54. (options, args) = parser.parse_args()
  55. if options.safe:
  56.     os.environ['USBCREATOR_SAFE'] = '1'
  57.  
  58. if options.trace:
  59.     if 'SUDO_USER' in os.environ:
  60.         filename = '%s/.usb-creator.trace' % \
  61.             os.path.expanduser('~' + os.environ['SUDO_USER'])
  62.     else:
  63.         filename = '%s/.usb-creator.trace' % \
  64.             os.path.expanduser('~')
  65.     trace_file = open(filename, 'w')
  66.     sys.settrace(_traceit)
  67.  
  68. if os.getuid() != 0:
  69.     args = ['gksu', 'gksu', '--desktop',
  70.     '/usr/share/applications/usb-creator.desktop', '--']
  71.     args.extend(sys.argv)
  72.     os.execvp(args[0], args)
  73.  
  74. # TODO: trap sigterm, hook into copy shutdown routine.
  75. f = GtkFrontend(options.iso,options.persistent)
  76.